﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EntityManage;

namespace ChatClient
{
    public partial class FormRegist : Form
    {
        public FormRegist()
        {
            InitializeComponent();
        }

        private void btnregist_Click(object sender, EventArgs e)
        {
            if (txtLoginID.Text == "")
            {
                MessageBox.Show("登录名不能为空！");
                txtLoginID.Focus();
                return;
            }
            if (txtPassword1.Text == "" || txtPassword2.Text == "")
            {
                MessageBox.Show("密码不能为空！");
                txtPassword1.Focus();
                return;
            }
            if (txtPassword1.Text != txtPassword2.Text)
            {
                MessageBox.Show("密码不相同！");
                txtPassword1.Focus();
                return;
            }
            if (txtNickName.Text == "")
            {
                MessageBox.Show("昵称不能为空！");
                txtNickName.Focus();
                return;
            }
            if (UserManager.Regist(txtLoginID.Text, txtPassword1.Text, txtNickName.Text))
            {
                MessageBox.Show("注册成功！");
                this.Close();
            }
            else
            {
                MessageBox.Show("注册失败！");
            }
        }

        private void txtLoginID_Leave(object sender, EventArgs e)
        {
            if (txtLoginID.Text == "")
            {
                return;
            }
            if (UserManager.CheckLoginExist(txtLoginID.Text))
            {
                MessageBox.Show("登录名已存在！");
                txtLoginID.Focus();
            }
        }
    }
}
